package cn.com.haopy.yue.ai.wx.service;


import cn.com.haopy.yue.ai.core.config.CheckProperties;
import cn.com.haopy.yue.ai.core.utils.HttpUtils;
import cn.com.haopy.yue.ai.wx.constant.CheckConstant;
import cn.com.haopy.yue.ai.wx.utils.CheckApiUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;


@Service
public class CheckReportService {

    @Autowired
    private CheckProperties checkProperties;

    public JSONArray checkList(String idcardNo, String name) throws Exception {
        Map<String, Object> params = new HashMap<>();
        params.put("idcardNo", idcardNo);
        params.put("name", name);
        params = CheckApiUtil.unionSign(params, checkProperties.getAppId(), checkProperties.getSecret());

        JSONObject data = HttpUtils.postJSON(checkProperties.getHost() + CheckConstant.reportList, null, params);

        JSONObject map = CheckApiUtil.handleResult(data);
        if (null != map) {
            return map.getJSONArray("data");
        }
        return null;
    }

    public JSONArray checkDetailData(String workNo) throws Exception {
        Map<String, Object> params = new HashMap<>();
        params.put("workNo", workNo);
        params = CheckApiUtil.unionSign(params, checkProperties.getAppId(), checkProperties.getSecret());

        JSONObject data = HttpUtils.postJSON(checkProperties.getHost() + CheckConstant.reportDataDetail, null, params);

        JSONObject map = CheckApiUtil.handleResult(data);
        if (null != map) {
            return map.getJSONArray("data");
        }
        return null;
    }


}
